//
//  SYDMyCarViewController.m
//  PinGJByOwnerSide
//
//  Created by lantaiyuan on 2017/8/8.
//  Copyright © 2017年 lantaiyuan. All rights reserved.
//

#import "SYDMyCarViewController.h"

@interface SYDMyCarViewController ()
@property (weak, nonatomic) IBOutlet UILabel *isCurrentCar;//是否当前车辆
@property (weak, nonatomic) IBOutlet UIView *InnerLayerView;
@property (weak, nonatomic) IBOutlet UIView *userMessageView;
@property (weak, nonatomic) IBOutlet UIImageView *carIcon;
@property (weak, nonatomic) IBOutlet UILabel *carNumber;
@property (weak, nonatomic) IBOutlet UILabel *carNBrand;
@property (weak, nonatomic) IBOutlet UIButton *carRegisterBtn;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *constraintWidth;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *constraintHeight;
@property (weak, nonatomic) IBOutlet UILabel *carRegisterLabel;
@property(nonatomic,strong)NSMutableArray *carList;

@end

@implementation SYDMyCarViewController
#pragma mark - 导航栏
- (void)navigationBarHandle{
    
    WEAKSELF
    [weakSelf backButtonAction:^{
        
        [weakSelf.navigationController popViewControllerAnimated:YES];
    }];
}

-(void)initMyCarData{
    WEAKSELF
    [[SYDNetwork shareTool]getMineBusIfonWithUserId:[YMSaveTool valueForKey:USER_ID] success:^(NSURLSessionDataTask *task, id responseObject) {
        @try {
            
            if ([responseObject[@"statusCode"]integerValue] == 200) {
                //NSLog(@"----%@",responseObject);
                self.carList = [MyCarModel mj_objectArrayWithKeyValuesArray:responseObject[@"obj"]];
                MyCarModel *model = self.carList[0];
                //是否当前使用车辆
                weakSelf.isCurrentCar.text = [model.isCurBus isEqualToString:@"1"] ? @"当前车辆": @"不是当前车辆";
                NSInteger boolShow = [model.status integerValue];
                weakSelf.carNBrand.text = model.busBrand;
                weakSelf.carNumber.text = model.busLicensePlate;
                weakSelf.carIcon.layer.cornerRadius = 62.5;
                weakSelf.carIcon.layer.masksToBounds = YES;
                [weakSelf.carIcon sd_setImageWithURL:[NSURL URLWithString:model.busPersonGroupUrl] placeholderImage:[UIImage imageNamed:@"icon_head_portrait2"]];
                if (boolShow == 1) {
                    self.carRegisterLabel.hidden = YES;
                    [self.userMessageView drawBorderWithCornerRadius:10];
                }else if (boolShow == 0){
                    self.carRegisterBtn.hidden = YES;
                    self.carRegisterLabel.text = @"审核失败";
                    self.carRegisterLabel.textColor = SUB_TITLE_COLOR;
                    self.carRegisterLabel.font  =[UIFont systemFontOfSize:16];
                    [self.carRegisterLabel drawBorderWithColor:GRAY_COLOR radius:15.5];
                }
            }
        } @catch (NSException *exception) {
            NSLog(@"---%@",exception.description);
        } @finally {
        }
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        NSLog(@"%@",error);
    }];
}
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.InnerLayerView.backgroundColor = GREEN_COLOR;
    self.navigationBar.title = @"我的车辆";
    [self navigationBarHandle];
    [self initMyCarData];
}
-(NSMutableArray *)carList{
    if (!_carList) {
        _carList = [NSMutableArray array];
    }
    return _carList;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
